<!DOCTYPE html>
<html>
<head>
    <title>Circular Motion Diagram</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        canvas {
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
    <canvas id="physicsCanvas" width="500" height="550"></canvas>
    <script>
        const canvas = document.getElementById('physicsCanvas');
        const ctx = canvas.getContext('2d');

        // Helper function to draw an arrow head
        function drawArrowHead(ctx, x, y, angle, size = 10) {
            ctx.save();
            ctx.beginPath();
            ctx.translate(x, y);
            ctx.rotate(angle);
            ctx.moveTo(0, 0);
            ctx.lineTo(-size, -size / 2);
            ctx.moveTo(0, 0);
            ctx.lineTo(-size, size / 2);
            ctx.stroke();
            ctx.restore();
        }

        // Diagram parameters
        const cx = canvas.width / 2;
        const cy = 250;
        const R = 150; // Radius of the large circle
        const theta = Math.PI / 3; // 60 degrees

        // Calculated positions
        const mass_x = cx + R * Math.sin(theta);
        const mass_y = cy + R * Math.cos(theta);

        // --- Start Drawing ---

        ctx.strokeStyle = 'black';
        ctx.fillStyle = 'black';
        ctx.lineWidth = 2;

        // 1. Draw the main circle
        ctx.beginPath();
        ctx.arc(cx, cy, R, 0, 2 * Math.PI);
        ctx.stroke();

        // 2. Draw the vertical axis of rotation (dashed)
        ctx.beginPath();
        ctx.setLineDash([6, 6]);
        ctx.moveTo(cx, cy - R - 50);
        ctx.lineTo(cx, cy + R + 50);
        ctx.stroke();

        // Reset to solid lines for subsequent drawings
        ctx.setLineDash([]);

        // 3. Draw the rotation symbol (ω) at the top
        const rot_y = cy - R - 25;
        const rot_r = 25;
        const rot_start_angle = Math.PI * 1.3;
        const rot_end_angle = Math.PI * 1.7;
        
        ctx.beginPath();
        // The arrow is curved like a smile, counter-clockwise
        ctx.arc(cx, rot_y + 10, rot_r, Math.PI * 0.2, Math.PI * 0.8);
        ctx.stroke();
        
        // Arrowhead for rotation (CCW)
        const arrow_angle = Math.PI * 0.8;
        const arrow_x = cx + rot_r * Math.cos(arrow_angle);
        const arrow_y = rot_y + 10 + rot_r * Math.sin(arrow_angle);
        const tangent = arrow_angle + Math.PI / 2;
        drawArrowHead(ctx, arrow_x, arrow_y, tangent, 8);
        
        ctx.font = 'italic 24px Times New Roman';
        ctx.fillText('ω', cx + rot_r + 10, rot_y + 15);
        
        // 4. Draw dashed lines from center
        ctx.beginPath();
        ctx.setLineDash([6, 6]);
        // Radius R
        ctx.moveTo(cx, cy);
        ctx.lineTo(mass_x, mass_y);
        // Horizontal radius r
        ctx.moveTo(cx, mass_y);
        ctx.lineTo(mass_x, mass_y);
        // Vertical segment for angle theta
        ctx.moveTo(cx, cy);
        ctx.lineTo(cx, mass_y);
        ctx.stroke();

        // 5. Draw the angle arc for θ
        ctx.beginPath();
        ctx.setLineDash([]);
        const angle_R_rad = Math.atan2(mass_y - cy, mass_x - cx);
        ctx.arc(cx, cy, 40, Math.PI / 2, angle_R_rad);
        ctx.stroke();
        
        // 6. Draw the right-angle mark
        ctx.beginPath();
        ctx.moveTo(cx, mass_y - 12);
        ctx.lineTo(cx + 12, mass_y - 12);
        ctx.lineTo(cx + 12, mass_y);
        ctx.stroke();
        
        // 7. Draw the mass 'm'
        ctx.beginPath();
        ctx.arc(mass_x, mass_y, 6, 0, 2 * Math.PI);
        ctx.fill();

        // 8. Draw the force vector F_i
        const force_length = 80;
        ctx.beginPath();
        ctx.moveTo(mass_x, mass_y);
        ctx.lineTo(mass_x + force_length, mass_y);
        ctx.stroke();
        drawArrowHead(ctx, mass_x + force_length, mass_y, 0, 10);

        // 9. Add all text labels
        ctx.font = 'italic 22px Times New Roman';
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';

        // Label O
        ctx.fillText('O', cx - 20, cy + 5);
        // Label R
        ctx.save();
        ctx.translate((cx + mass_x) / 2, (cy + mass_y) / 2);
        ctx.rotate(angle_R_rad);
        ctx.fillText('R', 0, -15);
        ctx.restore();
        // Label r
        ctx.fillText('r', cx + (mass_x - cx) / 2, mass_y - 20);
        // Label θ
        ctx.fillText('θ', cx + 25, cy + 30);
        // Label m
        ctx.fillText('m', mass_x + 18, mass_y + 3);
        // Label F_i
        ctx.fillText('F', mass_x + force_length + 15, mass_y);
        ctx.font = 'italic 16px Times New Roman';
        ctx.fillText('i', mass_x + force_length + 25, mass_y + 7);
        
        // 10. Add the figure caption
        ctx.font = '22px KaiTi'; // Font that supports Chinese characters
        ctx.textAlign = 'center';
        ctx.fillText('力图 3.13.1', cx, canvas.height - 30);
    </script>
</body>
</html>